﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    >

    <Style x:Key="RadarStyle" TargetType="{x:Type ItemsControl}">
        <Setter Property="Background" Value="#18426C"/>
        <Setter Property="Foreground" Value="#F9F9F9"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="BorderThickness" Value="5"/>
        <Setter Property="Margin" Value="3"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="c:RadarPanel.IsScanning" Value="False"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <c:RadarPanel IsItemsHost="True" RadialPadding="10" ItemRadius="17"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ItemsControl}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        
                        <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="{TemplateBinding Margin}" Background="{TemplateBinding BorderBrush}">
                            <UIElement.Clip>
                                <MultiBinding Converter="{x:Static cnv:CircleGeometryConverter.Default}">
                                    <Binding RelativeSource="{RelativeSource Mode=Self}" Path="ActualWidth"/>
                                    <Binding RelativeSource="{RelativeSource Mode=Self}" Path="ActualHeight"/>
                                </MultiBinding>
                            </UIElement.Clip>

                            <Border Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}">
                                <UIElement.Clip>
                                    <MultiBinding Converter="{x:Static cnv:CircleGeometryConverter.Default}">
                                        <Binding RelativeSource="{RelativeSource Mode=Self}" Path="ActualWidth"/>
                                        <Binding RelativeSource="{RelativeSource Mode=Self}" Path="ActualHeight"/>
                                    </MultiBinding>
                                </UIElement.Clip>

                                <Grid Height="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualWidth}" VerticalAlignment="Top">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <ScrollViewer x:Name="scrollViewer" Grid.RowSpan="3" Grid.ColumnSpan="2" CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                                        <ItemsPresenter/>
                                    </ScrollViewer>

                                    <Polygon x:Name="radarBeam" Grid.Row="1" Grid.Column="1" Opacity="0.5" Fill="#4455F7" Stretch="Fill" IsHitTestVisible="False" RenderTransformOrigin="0, 0.5" Visibility="Hidden">
                                        <Polygon.Points>
                                            <Point X="0" Y="0"/>
                                            <Point X="10" Y="-10"/>
                                            <Point X="10" Y="10"/>
                                        </Polygon.Points>

                                        <Polygon.RenderTransform>
                                            <RotateTransform x:Name="rotateTransform"/>
                                        </Polygon.RenderTransform>
                                    </Polygon>
                                </Grid>
                            </Border>
                        </Border>

                        <RepeatButton Grid.Row="1" Grid.Column="0" Command="ScrollBar.PageUpCommand" CommandTarget="{Binding ElementName=scrollViewer}" Content="&lt;" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20, 0, 0, 0"/>
                        <RepeatButton Grid.Row="1" Grid.Column="1" Command="ScrollBar.PageDownCommand" CommandTarget="{Binding ElementName=scrollViewer}" Content="&gt;" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0, 0, 20, 0"/>
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="c:RadarPanel.IsScanning" Value="True">
                            <Setter TargetName="radarBeam" Property="Visibility" Value="Visible"/>
                            <Trigger.EnterActions>
                                <BeginStoryboard Name="radarBeamAnimation">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="rotateTransform" Storyboard.TargetProperty="Angle" From="0.0" To="360.0" Duration="0:0:3" AutoReverse="False" RepeatBehavior="1"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="radarBeamAnimation"/>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RadarTextStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="9"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
    </Style>

    <Style x:Key="RadarToolTipStyle" TargetType="{x:Type ToolTip}">
        <Setter Property="Background" Value="Black"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="BorderThickness" Value="0"/>
    </Style>
    
    <Style x:Key="User_RadarItemStyle" TargetType="{x:Type ContentControl}">
        <Style.Resources>
            <Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource RadarToolTipStyle}"/>
        </Style.Resources>
        
        <Setter Property="ToolTip">
            <Setter.Value>
                <StackPanel Orientation="Vertical" Background="Black">
                    <Image Source="{Binding Converter={x:Static cnv:OdigoAvatarConverter.Default}}" Stretch="None"/>
                    <TextBlock Text="{Binding Name}" Margin="2, 0, 2, 0" HorizontalAlignment="Center"/>
                </StackPanel>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <StackPanel Orientation="Vertical" Margin="2">
                        <Image x:Name="genderImage" Source="OdigoImages/RadarMale.png" Stretch="None"/>
                        <TextBlock Text="{Binding Name}" MaxWidth="{Binding ElementName=genderImage, Path=ActualWidth}" Style="{StaticResource RadarTextStyle}"/>
                    </StackPanel>
                    
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Gender}" Value="Female">
                            <Setter TargetName="genderImage" Property="Source" Value="OdigoImages/RadarFemale.png"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>